package com.jxpowernode.bitcon.btcrpccode;

import com.alibaba.fastjson.JSONObject;
import com.jxpowernode.bitcon.Constants;
import com.jxpowernode.bitcon.bean.rpcbtc.ChainResult;
import com.jxpowernode.bitcon.bean.rpcbtc.GetChainTipsHash;
import com.jxpowernode.bitcon.request.HttpUtils;
import com.jxpowernode.bitcon.service.btcservice.GetBitconService;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author: Lixuewei
 * @Email:1410511702@qq.com
 * @Desc: 该类用户实现通过rpc访问调用btc的getChainTips方法
 * @Date: 2021/12/16 16:09
 */
public class GetChainTips {

    /**
     * 该方法用于获取全部区块头
     * @return 返回全部区块头的值
     */
    public ChainResult[] getChainTips(){
        GetBitconService service = new GetBitconService();
        Map<String, String> bitcon = service.getBitcon();
        Map<String,Object> boby = new HashMap<>();
        boby.put("id","1001");
        boby.put("method","getchaintips");
        byte[] data = JSONObject.toJSONBytes(boby);
        String result = HttpUtils.post(Constants.RPC_URL, bitcon, data);
        GetChainTipsHash getChainTipsHash = JSONObject.parseObject(result, GetChainTipsHash.class);
        return getChainTipsHash.getResult();

    }
}
